------------------ fgui require start ------------------
------------------  fgui require end  ------------------

local UIGuildLogSkin = Class("UIGuildLogSkin");
local GuildLogItem = require "View/UIGuild/Skin/GuildLogItemSkin"

function UIGuildLogSkin:ctor(com)
    ------------------ fgui事件绑定start ------------------
    self:bindChild(com);
    self.btn_blackbackground.onClick:Add(self.onTouch_Btn_blackbackground,self);
    self.list_Logdetails.onClickItem:Add(self.onClickItem_List_Logdetails,self);
    self.list_Logdetails.itemRenderer = function(index,obj) self:onRender_List_LogdetailsItem(index,obj); end;
    self:init();
    ------------------  fgui事件绑定end  ------------------
end

function UIGuildLogSkin:bindChild(com)
    ------------------ fgui变量绑定start ------------------
    self.fguiObj = com;
    self.btn_blackbackground = com:GetChild("Btn_blackbackground");
    self.text_close = com:GetChild("Text_close");
    self.text_journal = com:GetChild("Text_journal");
    self.list_Logdetails = com:GetChild("List_Logdetails");
    ------------------  fgui变量绑定end  ------------------
end

function UIGuildLogSkin:init() 
    self.listItems = {};
    self.eventData = {}
    self:formatData();
    self.list_Logdetails.numItems = #self.eventData;
end

function UIGuildLogSkin:formatData()
    self.eventData = {}
    local events = logicMgr.GuildManager.unionEventLogs or {};
    local data = {}
    for _ , v in ipairs(events) do
        local date = formatUnixTime2Date(tonumber(tostring(v.eventTime)));
        local timeStr = date.year.."-"..date.month.."-"..date.day;
        if data.time ~= timeStr then
            data = {}
            data["time"] = timeStr;
            data["msgs"] = {}
            table.insert(self.eventData,1,data);
        end
        if v.eventType == 0 then
            table.insert(data["msgs"]  , string.format(getLanguage("GuildInvestment_1078"),v.params[1]));
        elseif v.eventType == 1 then
            table.insert(data["msgs"]  , string.format(getLanguage("GuildInvestment_1079"),v.params[1]));
        elseif v.eventType == 2 then
            if GuildManager.isChairman(tonumber(v.params[4])) then
                table.insert(data["msgs"]  , string.format(getLanguage("GuildInvestment_1081"),v.params[1],v.params[2]));
            else 
                table.insert(data["msgs"]  , string.format(getLanguage("GuildInvestment_1082"),v.params[2]));
            end
        elseif v.eventType == 3 then
            table.insert(data["msgs"]  , string.format(getLanguage("GuildInvestment_1083"),v.params[2]));
        elseif v.eventType == 4 then
            table.insert(data["msgs"], string.format(getLanguage("GuildInvestment_1080"), v.params[1]));
        elseif v.eventType == 6 then
            table.insert(data["msgs"], string.format(getLanguage("GuildInvestment_1201"), v.params[1]));
        end
    end
end

function UIGuildLogSkin:OnDestroy()
    ------------------ fgui事件移除start ------------------
    self:beforeDestroy();
    self.btn_blackbackground.onClick:Clear();
    self.list_Logdetails.onClickItem:Clear();
    self.list_Logdetails.itemRenderer = nil;
    ------------------  fgui事件移除end  ------------------
end

function UIGuildLogSkin:onTouch_Btn_blackbackground(obj) end

function UIGuildLogSkin:onClickItem_List_Logdetails(context) end

function UIGuildLogSkin:onRender_List_LogdetailsItem(index,obj) 
    local item = self.listItems[obj];
    if item == nil then
        item = GuildLogItem.New(obj);
        self.listItems[obj] = item;
    end
    item:onRender(self.eventData[index+1]);
end

------------------  ↑ fgui事件句柄 ↑  ------------------

function UIGuildLogSkin:setCloseCallback(func,target)
    self.btn_blackbackground.onClick:Add(func,target);
end

function UIGuildLogSkin:beforeDestroy() end

return UIGuildLogSkin;
